python check if array alternating

34

def alternating(list):
  for i  in range(1,len(list)):
    if (((list[i]>list[i+1]) and (list[i]>list[i-1])) or ((list[i]  <list[i+1]) and (list[i]<list[i-1]))) :
      return True
    else:
      return False

Comments

Submit
0 Comments